'use strict';
// const uniCloud = require('uni-cloud-sdk');

exports.main = async (event, context) => {
	const {
		files
	} = event;
	const {
		tempFilePaths
	} = files;

	try {
		const fileData = [];

		// 上传所有图片，并记录上传后的文件信息
		for (let i = 0; i < tempFilePaths.length; i++) {
			const file = await uniCloud.uploadFile({
				cloudPath: `images/${Date.now()}-${Math.floor(Math.random() * 1000000)}.png`,
				filePath: tempFilePaths[i]
			});

			fileData.push(file);
		}

		return {
			code: 0,
			message: '上传成功',
			data: fileData
		};
	} catch (error) {
		return {
			code: -1,
			message: '上传失败：' + error.message,
			data: error
		};
	}
};
